package Boke2;

public class Notify {
        //创建两个用于线程加锁的对象
        public static Object loker1=new Object();
        public static Object loker2=new Object();

        public static void main(String[] args) {
            //新线程t1
            Thread t1=new Thread(()->{
                System.out.println("t1线程开始 调用wait之前");
                //让t1线程进入阻塞等待
                synchronized (loker1){
                    try {
                        //让被加锁的loker1对象进入阻塞等待
                        loker1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("t1线程结束 wait阻塞等待解除");
            });
            t1.start();

            //创建t2线程用于唤醒t1线程
            Thread t2=new Thread(()->{
                //必须先对同一个对象加锁(loker1)
                synchronized (loker1){
                    try {
                        System.out.println("t2线程启动：唤醒t1线程中");
                        Thread.sleep(2000);
                        //唤醒线程t1
                        loker1.notify();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            });
            t2.start();
        }

}
